# import boto3
# import sys
# import csv



# lbclient = boto3.client('elbv2')
# es2client = boto3.client('ec2')


# # lb_name = sys.argv[1]
# # tg_name = sys.argv[2]
# # tg_port = int(sys.argv[3])


#  # parameter lb_name SLB 名称，lb_globle 公网或私网， lb_type TCP 或 HTTP 

# def creatlb(lb_name, lb_globle, lb_type):
#     create_load_balancer = lbclient.create_load_balancer(
#         Name=lb_name,
#         Scheme=lb_globle,
#         SecurityGroups=[
#             'sg-05bb917a95eb1ae16',
#         ],
#         Subnets=[
#             'subnet-08c6ecf890b970ae6',
#             'subnet-0921d315f1cd1818e',
#         ],
#         Type=lb_type,
#     )
#     lb_arn = create_load_balancer['LoadBalancers'][0]['LoadBalancerArn']
#     lb_dns = create_load_balancer['LoadBalancers'][0]['DNSName']
#     return lb_arn, lb_dns

# def creatlb_tcp(lb_name, lb_globle, lb_type):
#     create_load_balancer = lbclient.create_load_balancer(
#         Name=lb_name,
#         Scheme=lb_globle,
#         Subnets=[
#             'subnet-08c6ecf890b970ae6',
#             'subnet-0921d315f1cd1818e',
#         ],
#         Type=lb_type,
#     )
#     lb_arn = create_load_balancer['LoadBalancers'][0]['LoadBalancerArn']
#     lb_dns = create_load_balancer['LoadBalancers'][0]['DNSName']
#     return lb_arn, lb_dns

# # tg_name 目标组名称，tg_port 目标组端口， lb_protocol 目标组协议类型(http,tcp,https等)
# def createtg(tg_name, tg_port, lb_protocol):
#     create_target_group = lbclient.create_target_group(
#         Name=tg_name,
#         Port=tg_port,
#         Protocol=lb_protocol,
#         VpcId='vpc-014e112668bec5d3d',
#         HealthCheckPath='/helath'
#     )
#     tg_arn = create_target_group['TargetGroups'][0]['TargetGroupArn']
#     return tg_arn

# def createtg_tcp(tg_name, tg_port, lb_protocol):
#     create_target_group = lbclient.create_target_group(
#         Name=tg_name,
#         Port=tg_port,
#         Protocol=lb_protocol,
#         VpcId='vpc-014e112668bec5d3d',
#     )
#     tg_arn = create_target_group['TargetGroups'][0]['TargetGroupArn']
#     return tg_arn


# def createlt(lb_arn, tg_arn, lt_port, lb_protocol):
#     crete_listener = lbclient.create_listener(
#         DefaultActions=[
#             {
#                 'TargetGroupArn': tg_arn,
#                 'Type': 'forward',
#             },
#         ],
#         LoadBalancerArn=lb_arn,
#         Port=lt_port,
#         Protocol=lb_protocol,
#     )
#     return crete_listener
# def getec2info(privat_ip_adderss):
#     describe_instances = es2client.describe_instances(
#         Filters=[
#             {
#                 'Name': 'network-interface.addresses.private-ip-address',
#                 'Values': [
#                     privat_ip_adderss,
#                 ]
#             },
#         ],
#     )
#     return describe_instances


# if __name__ == "__main__":
#     with open('data.csv') as readdata:
#         reader_from_csv = csv.reader(readdata)
#         rownum = 1
#         with open('result.csv', 'a+', newline='') as writedata:
#             writer_to_csv = csv.writer(writedata)
#             for row in reader_from_csv:
#                 if 'slb' in row[3]:
#                     lb_name = row[3]
#                     if 'opengate' in row[3]:
#                         lb_globle = 'internet-facing'
#                     else:
#                         lb_globle = 'internal'
#                     if row[-1] == "tcp":
#                         lb_type = "network"
#                         lb_protocol = "TCP"
#                         tg_name = str.format("{}-tcp", row[3])
#                     else:
#                         lb_type = "application"
#                         lb_protocol = "HTTP"
#                         tg_name = str.format("{}-http", row[3])
#                     tg_port = int(row[-2])
#                     if rownum > 9:
#                         rowstr = str.format("ELB-{}", rownum)
#                     else:
#                         rowstr = str.format("ELB-0{}", rownum)
#                     if row[-1] == "tcp":
#                         elb = creatlb_tcp(lb_name, lb_globle, lb_type)
#                         tg_arn = createtg_tcp(tg_name, tg_port, lb_protocol)
#                     else:
#                         elb = creatlb(lb_name, lb_globle, lb_type)
#                         tg_arn = createtg(tg_name, tg_port, lb_protocol)
#                     lb_arn = elb[0]
#                     lb_dns = elb[1]
#                     lt_port = int(row[-3])
#                     createlt(lb_arn, tg_arn, lt_port, lb_protocol)
#                     row[0] = rowstr
#                     row[1] = lb_arn
#                     row[2] = tg_arn
#                     row[4] = lb_dns
#                     writer_to_csv.writerow(row)
#                     rownum += 1
#                     print(str.format("创建ELB{}成功", row[3]))
#                 else:
#                     writer_to_csv.writerow(row)
#                     print("这是ES2主机，无需创建")
